package cn.stacey.day03;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class DemoPlaceFlower {
	public static boolean canPlaceFlowers(int[] flowerbed, int n) {
		int count = 0;
		for (int i = 0; i < flowerbed.length; i++) {
			// 检查当前元素是否为0，并且，前面一位是0，后面一位也是0
			if (flowerbed[i] == 1) {
				continue;
			} else {
				if ((i == 0 || flowerbed[i - 1] == 0) 
						&& (i == flowerbed.length - 1 || flowerbed[i + 1] == 0)) {
					flowerbed[i] = 1;
					count++;
				}
			}
		}
		
		return count >= n;
	}
	
	public static boolean hasCommonDivisor() {
		return true;
	}
	
	@Test
	public void test1() {
		assertTrue(canPlaceFlowers(new int[] {0, 0, 0}, 1));
		assertTrue(canPlaceFlowers(new int[] {0, 0, 0}, 2));
		assertTrue(canPlaceFlowers(new int[] {0, 0, 0}, 3) == false);
		
		assertTrue(canPlaceFlowers(new int[] {1, 0, 0, 0}, 1));
		assertTrue(canPlaceFlowers(new int[] {1, 0, 0, 0}, 2) == false);
	}
	
	@Test
	public void test2() {
		System.out.println(hasCommonDivisor());
	}
}